using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class SettingPanel : BasePanel<SettingPanel>
{
    public MyGUISlider sliderMusic;
    public MyGUISlider sliderSound;
    public MyGUIToggle toggleMusic;
    public MyGUIToggle toggleSound;
    public MyGUIButton btnClose;
    private void Start()
    {
        sliderMusic.ChangeValue += (v) => GameDataManager.Instance.ChangeBGMValue(v);
        sliderSound.ChangeValue += (v) => GameDataManager.Instance.ChangeSoundValue(v);
        toggleMusic.ChangeValue += (v) => GameDataManager.Instance.OpenOrCloseBGM(v);
        toggleSound.ChangeValue += (v) => GameDataManager.Instance.OpenOrCloseSound(v);
        btnClose.onClick += () =>
        {
            HidePanel();
            //判断当前所在场景
            if (SceneManager.GetActiveScene().name.Equals("BeginScene"))
            {
                BeginPanel.Instance.ShowPanel();
            }
        };
        HidePanel();
    }
    //更新面板数据
    public void UpdatePanelInfo()
    {
        MusicData musicData = GameDataManager.Instance.musicData;
        sliderMusic.nowVale = musicData.bgmValue;
        sliderSound.nowVale = musicData.soundValue;
        toggleMusic.isSel = musicData.isOpenBGM;
        toggleSound.isSel = musicData.isOpenSound;
    }
    public override void ShowPanel()
    {
        base.ShowPanel();
        UpdatePanelInfo();
    }
}
